package com.daryl.jcu_project1_creditscoreform;

import java.text.NumberFormat;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.NavUtils;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnKeyListener;

public class Display_form_fund_statement extends Activity {

	private TextView tvTotalCostCalculated;
	private TextView tvTotalFundingCalculated;

	private EditText purchasePrice;
	private EditText etFinanaceExitPenaltyFee;
	private EditText etStampDutyRegMortageTransferOfLand;
	private EditText etLegalAndSearchFee;
	private EditText etMortgageInsurancePremium;
	private EditText etSolicitorFees;
	private EditText etOtherCosts;
	private EditText etDepositePaid;
	private EditText etSavingsContribution;
	private EditText etFirstHomeOwnersGrant;
	private EditText etGifts;
	private EditText etSaleProceeds;
	private EditText etOthers;
	private EditText etOthersSpecify;

	private String vPurchasePrice;
	private String vTotalCostCalculated;
	private String vTotalFundingCalculated;
	private String vFinanaceExitPenaltyFee;
	private String vStampDutyRegMortageTransferOfLand;
	private String vLegalAndSearchFee;
	private String vMortgageInsurancePremium;
	private String vSolicitorFees;
	private String vOtherCosts;
	private String vDepositePaid;
	private String vSavingsContribution;
	private String vFirstHomeOwnersGrant;
	private String vGifts;
	private String vSaleProceeds;
	private String vOthers;
	private String vOthersSpecify;
	
	private double dblPurchasePrice;
	private double dblTotalCostCalculated;
	private double dblNewTotalCostCalculated;
	private double dblTotalFundingCalculated;
	private double dblNewTotalFundingCalculated;
	private double dblFinanaceExitPenaltyFee;
	private double dblStampDutyRegMortageTransferOfLand;
	private double dblLegalAndSearchFee;
	private double dblMortgageInsurancePremium;
	private double dblSolicitorFees;
	private double dblOtherCosts;
	private double dblSaleProceeds;
	private double dblOthers;
	
	
	private double dblDepositePaid;
	private double dblSavingsContribution;
	private double dblFirstHomeOwnersGrant;
	private double dblGifts;

	public static int nextpage = 0;
	public static int previouspage = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_display_form_fund_statement);
		Display_form_employment_details de = new Display_form_employment_details();
		// Show the Up button in the action bar.
		methods md = new methods();
		
		/*getPurchasePrice();
		getRefinanaceExitPenaltyFee();
		getStampDutyRegMortageTransferOfLand();
		getLegalAndSearchFee();
		getMortgageInsurancePremium();
		getSolicitorFees();
		getOtherCosts();*/
		
		System.out.println("get Deposite 1");

		if (de.nextpage > 0) {
			System.out.println("de next page " + de.nextpage);
			setTotalCost();
			setPurchasePrice();
			setRefinanaceExitPenaltyFee();
			setStampDutyRegMortageTransferOfLand();
			setLegalAndSearchFee();
			setMortgageInsurancePremium();
			setSolicitorFees();
			setOtherCosts();
			
			setDepositePaid();
			setSavingsContribution();
			setTotalFund();
			setFirstHomeOwnersGrant();
			setGifts();
			setSaleProceeds();
			setOthers();
			setOthersSpecify();
			
			System.out.println("Total Cost: "
					+ md.retriveSharePreference(this, "vPurchasePrice",
							"dTotalCostCalculated"));
			
			
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_display_form_fund_statement,
				menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void nextPage(View view) {
		Intent intent_next = new Intent(this,
				Display_form_loan_structure_and_purpose.class);
		startActivity(intent_next);
		methods md = new methods();
		
		int retriveValue = 0;
		
		getPurchasePrice();
		System.out.println("get Deposite 2");
		getRefinanaceExitPenaltyFee();
		
		getTotalCost();
		getStampDutyRegMortageTransferOfLand();
		getLegalAndSearchFee();
		getMortgageInsurancePremium();
		getSolicitorFees();
		getOtherCosts();
		
		getDepositePaid();
		getSavingsContribution();
		getFirstHomeOwnersGrant();
		getGifts();
		getSaleProceeds();
		getOthers();
		getOthersSpecify();
		
		getTotalFund();
		
		if(md.retriveShareIntPreference(this,retriveValue,"previousPage4")>0){ 
			nextpage++;
		}
	}

	public void previousPage(View view) {
		Intent intent_previous = new Intent (this, Display_form_employment_details.class);
		startActivity(intent_previous);
		methods md = new methods();

		
		
		md.editorShareIntPreferences(this, "previousPage3", 1);
		getPurchasePrice();
		System.out.println("get Deposite 3");
		getRefinanaceExitPenaltyFee();
		
		getTotalCost();
		getStampDutyRegMortageTransferOfLand();
		getLegalAndSearchFee();
		getMortgageInsurancePremium();
		getSolicitorFees();
		getOtherCosts();
		
		getDepositePaid();
		getSavingsContribution();
		getFirstHomeOwnersGrant();
		getGifts();
		getSaleProceeds();
		getOthers();
		getOthersSpecify();
		
		getTotalFund();
		System.out.println("fund statement previous page ");
		previouspage++;
	}

	

	// get purchase price
	public void getPurchasePrice() {
		variables vb = new variables();
		methods md = new methods();
		purchasePrice = (EditText) findViewById(R.id.etPurchasePrice);
		
		vPurchasePrice = purchasePrice.getText().toString();
		
				  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
					SharedPreferences.Editor editor = preferences.edit();
					
					// XXX do something
					System.out.println("vDepositePaid2 " + vPurchasePrice);
					vPurchasePrice = purchasePrice.getText().toString();
					
					Log.d("retriveValue", "log test 1 " + vPurchasePrice);
					
					System.out.println("vDepositePaid3 " + vPurchasePrice);
					
					
					Log.d("retriveValue", "log test 2 " + preferences.getString("dTotalCostCalculated", "0"));

					try {
						
						
						// store string purchase price
						editor.putString("dPurchasePrice", vPurchasePrice);
						editor.commit();
												
						//convert purchase price to double
						dblPurchasePrice = Double.parseDouble(vPurchasePrice);	
						
						//get total cost from storage
						String retriveValue = preferences.getString("dTotalCostCalculated", "0");
						Log.d("retriveValue", "log test 4 " + retriveValue);
						
						// convert to double
						dblTotalCostCalculated = Double.parseDouble(retriveValue);
						
						//calculate new total cost double
						dblNewTotalCostCalculated = dblPurchasePrice + dblTotalCostCalculated;
						
						//convert new total cost calculated and convert to string
						 String stringNewTotalCostCalculated;
						stringNewTotalCostCalculated = String.valueOf(dblNewTotalCostCalculated);
						Log.d("retriveValue", "log test 5 " + stringNewTotalCostCalculated);
						
						//textview Total Cost Calculated
						tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
						
						//insert new total cost to storage
						editor.putString("dTotalCostCalculated", stringNewTotalCostCalculated);
						editor.commit();
						
						tvTotalCostCalculated.setText(stringNewTotalCostCalculated);
						
					} catch (NumberFormatException nfe) {
						System.out.println("num format exception " + nfe);
					} catch (NullPointerException ne){
						System.out.println("null pointer exception " + ne);
					}
			  }
		

	public void setPurchasePrice() {

		methods md = new methods();

		purchasePrice = (EditText) findViewById(R.id.etPurchasePrice);
		purchasePrice.setText(md.retriveSharePreference(this, "vPurchasePrice",
				"dPurchasePrice"));
		System.out.println("set purchase price "
				+ md.retriveSharePreference(this, "vPurchasePrice",
						"dPurchasePrice"));
		
		System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vTotalCost", "dDepositPaid"));

	}
	
	
	// get refinance / exit penalty fee
		public void getRefinanaceExitPenaltyFee() {
			variables vb = new variables();
			methods md = new methods();
			etFinanaceExitPenaltyFee = (EditText) findViewById(R.id.etRefinance);
			
			//vPurchasePrice = etfinanaceExitPenaltyFee.getText().toString();
			
					  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
						SharedPreferences.Editor editor = preferences.edit();
						
						// XXX do something
						System.out.println("vFinanaceExitPenaltyFee " + vFinanaceExitPenaltyFee);
						vFinanaceExitPenaltyFee = etFinanaceExitPenaltyFee.getText().toString();
						
						Log.d("retriveValue", "log test 1 vFinanaceExitPenaltyFee " + vFinanaceExitPenaltyFee);
						
						
						Log.d("retriveValue", "log test 2 vFinanaceExitPenaltyFee " + preferences.getString("dTotalCostCalculated", "0"));

						try {
							
							
							// store string purchase price
							editor.putString("dFinanaceExitPenaltyFee", vFinanaceExitPenaltyFee);
							editor.commit();
													
							//convert purchase price to double
							dblFinanaceExitPenaltyFee = Double.parseDouble(vFinanaceExitPenaltyFee);	
							
							//get total cost from storage
							String retriveValue = preferences.getString("dTotalCostCalculated", "0");
							Log.d("retriveValue", "log test 4 vFinanaceExitPenaltyFee " + retriveValue);
							
							// convert to double
							dblTotalCostCalculated = Double.parseDouble(retriveValue);
							
							//calculate new total cost double
							dblNewTotalCostCalculated = dblFinanaceExitPenaltyFee + dblTotalCostCalculated;
							
							//convert new total cost calculated and convert to string
							 String stringNewTotalCostCalculated;
							stringNewTotalCostCalculated = String.valueOf(dblNewTotalCostCalculated);
							Log.d("retriveValue", "log test 5 " + stringNewTotalCostCalculated);
							
							//textview Total Cost Calculated
							tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
							
							//insert new total cost to storage
							editor.putString("dTotalCostCalculated", stringNewTotalCostCalculated);
							editor.commit();
							
							tvTotalCostCalculated.setText(stringNewTotalCostCalculated);
							
						} catch (NumberFormatException nfe) {
							System.out.println("num format exception " + nfe);
						} catch (NullPointerException ne){
							System.out.println("null pointer exception " + ne);
						}
				  }
			

		public void setRefinanaceExitPenaltyFee() {

			methods md = new methods();

			etFinanaceExitPenaltyFee = (EditText) findViewById(R.id.etRefinance);
			etFinanaceExitPenaltyFee.setText(md.retriveSharePreference(this, "vFinanaceExitPenaltyFee",
					"dFinanaceExitPenaltyFee"));
			System.out.println("set purchase price "
					+ md.retriveSharePreference(this, "vFinanaceExitPenaltyFee",
							"dFinanaceExitPenaltyFee"));
			
			System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vFinanaceExitPenaltyFee", "dFinanaceExitPenaltyFee"));

		}
		
		
		
		// get stamp duty / registration on mortage and transfer of land
				public void getStampDutyRegMortageTransferOfLand() {
					variables vb = new variables();
					methods md = new methods();
					etStampDutyRegMortageTransferOfLand = (EditText) findViewById(R.id.etStampDuty);
					
					//vPurchasePrice = etfinanaceExitPenaltyFee.getText().toString();
					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vStampDutyRegMortageTransferOfLand " + vStampDutyRegMortageTransferOfLand);
								vStampDutyRegMortageTransferOfLand = etStampDutyRegMortageTransferOfLand.getText().toString();
								
								Log.d("retriveValue", "log test 1 vStampDutyRegMortageTransferOfLand " + vStampDutyRegMortageTransferOfLand);
								
								
								Log.d("retriveValue", "log test 2 vStampDutyRegMortageTransferOfLand " + preferences.getString("dTotalCostCalculated", "0"));

								try {
									
									
									// store string purchase price
									editor.putString("dStampDutyRegMortageTransferOfLand", vStampDutyRegMortageTransferOfLand);
									editor.commit();
															
									//convert purchase price to double
									dblStampDutyRegMortageTransferOfLand = Double.parseDouble(vStampDutyRegMortageTransferOfLand);	
									
									//get total cost from storage
									String retriveValue = preferences.getString("dTotalCostCalculated", "0");
									Log.d("retriveValue", "log test 4 vStampDutyRegMortageTransferOfLand " + retriveValue);
									
									// convert to double
									dblTotalCostCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total cost double
									dblNewTotalCostCalculated = dblStampDutyRegMortageTransferOfLand + dblTotalCostCalculated;
									
									//convert new total cost calculated and convert to string
									 String stringNewTotalCostCalculated;
									stringNewTotalCostCalculated = String.valueOf(dblNewTotalCostCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalCostCalculated);
									
									//textview Total Cost Calculated
									tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
									
									//insert new total cost to storage
									editor.putString("dTotalCostCalculated", stringNewTotalCostCalculated);
									editor.commit();
									
									tvTotalCostCalculated.setText(stringNewTotalCostCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
				

				public void setStampDutyRegMortageTransferOfLand() {

					methods md = new methods();

					etStampDutyRegMortageTransferOfLand = (EditText) findViewById(R.id.etStampDuty);
					etStampDutyRegMortageTransferOfLand.setText(md.retriveSharePreference(this, "vStampDutyRegMortageTransferOfLand",
							"dStampDutyRegMortageTransferOfLand"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vStampDutyRegMortageTransferOfLand",
									"dStampDutyRegMortageTransferOfLand"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vStampDutyRegMortageTransferOfLand", "dStampDutyRegMortageTransferOfLand"));

				}
				
				
				
				
				// get legal and search fee
				public void getLegalAndSearchFee() {
					variables vb = new variables();
					methods md = new methods();
					etLegalAndSearchFee = (EditText) findViewById(R.id.etLegalAndSearchFees);
					
					//vPurchasePrice = etfinanaceExitPenaltyFee.getText().toString();
					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vLegalAndSearchFee " + vLegalAndSearchFee);
								vLegalAndSearchFee = etLegalAndSearchFee.getText().toString();
								
								Log.d("retriveValue", "log test 1 vLegalAndSearchFee " + vLegalAndSearchFee);
								
								
								Log.d("retriveValue", "log test 2 vLegalAndSearchFee " + preferences.getString("dTotalCostCalculated", "0"));

								try {
									
									
									// store string purchase price
									editor.putString("dLegalAndSearchFee", vLegalAndSearchFee);
									editor.commit();
															
									//convert purchase price to double
									dblLegalAndSearchFee = Double.parseDouble(vLegalAndSearchFee);	
									
									//get total cost from storage
									String retriveValue = preferences.getString("dTotalCostCalculated", "0");
									Log.d("retriveValue", "log test 4 vStampDutyRegMortageTransferOfLand " + retriveValue);
									
									// convert to double
									dblTotalCostCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total cost double
									dblNewTotalCostCalculated = dblLegalAndSearchFee + dblTotalCostCalculated;
									
									//convert new total cost calculated and convert to string
									 String stringNewTotalCostCalculated;
									stringNewTotalCostCalculated = String.valueOf(dblNewTotalCostCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalCostCalculated);
									
									//textview Total Cost Calculated
									tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
									
									//insert new total cost to storage
									editor.putString("dTotalCostCalculated", stringNewTotalCostCalculated);
									editor.commit();
									
									tvTotalCostCalculated.setText(stringNewTotalCostCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
				

				public void setLegalAndSearchFee() {

					methods md = new methods();

					etLegalAndSearchFee = (EditText) findViewById(R.id.etLegalAndSearchFees);
					etLegalAndSearchFee.setText(md.retriveSharePreference(this, "vLegalAndSearchFee",
							"dLegalAndSearchFee"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vLegalAndSearchFee",
									"dLegalAndSearchFee"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vLegalAndSearchFee", "dLegalAndSearchFee"));

				}
				
				
				
				// get legal and search fee
				public void getMortgageInsurancePremium() {
					variables vb = new variables();
					methods md = new methods();
					etMortgageInsurancePremium = (EditText) findViewById(R.id.etMortgageInsurancePremium);
					
					//vPurchasePrice = etfinanaceExitPenaltyFee.getText().toString();
					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vMortgageInsurancePremium " + vMortgageInsurancePremium);
								vMortgageInsurancePremium = etMortgageInsurancePremium.getText().toString();
								
								Log.d("retriveValue", "log test 1 vMortgageInsurancePremium " + vMortgageInsurancePremium);
								
								
								Log.d("retriveValue", "log test 2 vMortgageInsurancePremium " + preferences.getString("dTotalCostCalculated", "0"));

								try {
									
									
									// store string purchase price
									editor.putString("dMortgageInsurancePremium", vMortgageInsurancePremium);
									editor.commit();
															
									//convert purchase price to double
									dblMortgageInsurancePremium = Double.parseDouble(vMortgageInsurancePremium);	
									
									//get total cost from storage
									String retriveValue = preferences.getString("dTotalCostCalculated", "0");
									Log.d("retriveValue", "log test 4 vMortgageInsurancePremium " + retriveValue);
									
									// convert to double
									dblTotalCostCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total cost double
									dblNewTotalCostCalculated = dblMortgageInsurancePremium + dblTotalCostCalculated;
									
									//convert new total cost calculated and convert to string
									 String stringNewTotalCostCalculated;
									stringNewTotalCostCalculated = String.valueOf(dblNewTotalCostCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalCostCalculated);
									
									//textview Total Cost Calculated
									tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
									
									//insert new total cost to storage
									editor.putString("dTotalCostCalculated", stringNewTotalCostCalculated);
									editor.commit();
									
									tvTotalCostCalculated.setText(stringNewTotalCostCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
				

				public void setMortgageInsurancePremium() {

					methods md = new methods();

					etMortgageInsurancePremium = (EditText) findViewById(R.id.etMortgageInsurancePremium);
					etMortgageInsurancePremium.setText(md.retriveSharePreference(this, "vMortgageInsurancePremium",
							"dMortgageInsurancePremium"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vMortgageInsurancePremium",
									"dMortgageInsurancePremium"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vMortgageInsurancePremium", "dMortgageInsurancePremium"));

				}
				
				
				// get legal and search fee
				public void getSolicitorFees() {
					variables vb = new variables();
					methods md = new methods();
					etSolicitorFees = (EditText) findViewById(R.id.etSolicitorFees);
					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vSolicitorFees " + vSolicitorFees);
								vSolicitorFees = etSolicitorFees.getText().toString();
								
								Log.d("retriveValue", "log test 1 vSolicitorFees " + vSolicitorFees);
								
								
								Log.d("retriveValue", "log test 2 vSolicitorFees " + preferences.getString("dTotalCostCalculated", "0"));

								try {
									
									
									// store string purchase price
									editor.putString("dSolicitorFees", vSolicitorFees);
									editor.commit();
															
									//convert purchase price to double
									dblSolicitorFees = Double.parseDouble(vSolicitorFees);	
									
									//get total cost from storage
									String retriveValue = preferences.getString("dTotalCostCalculated", "0");
									Log.d("retriveValue", "log test 4 vSolicitorFees " + retriveValue);
									
									// convert to double
									dblTotalCostCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total cost double
									dblNewTotalCostCalculated = dblSolicitorFees + dblTotalCostCalculated;
									
									//convert new total cost calculated and convert to string
									 String stringNewTotalCostCalculated;
									stringNewTotalCostCalculated = String.valueOf(dblNewTotalCostCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalCostCalculated);
									
									//textview Total Cost Calculated
									tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
									
									//insert new total cost to storage
									editor.putString("dTotalCostCalculated", stringNewTotalCostCalculated);
									editor.commit();
									
									tvTotalCostCalculated.setText(stringNewTotalCostCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
					

				public void setSolicitorFees() {

					methods md = new methods();

					etSolicitorFees = (EditText) findViewById(R.id.etSolicitorFees);
					etSolicitorFees.setText(md.retriveSharePreference(this, "vSolicitorFees",
							"dSolicitorFees"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vSolicitorFees",
									"dSolicitorFees"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vSolicitorFees", "dSolicitorFees"));

				}
		
				
				// get other cost
				public void getOtherCosts() {
					variables vb = new variables();
					methods md = new methods();
					etOtherCosts = (EditText) findViewById(R.id.etOtherCosts);

					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vOtherCosts " + vOtherCosts);
								vOtherCosts = etOtherCosts.getText().toString();
								
								Log.d("retriveValue", "log test 1 vOtherCosts " + vSolicitorFees);
								
								
								Log.d("retriveValue", "log test 2 vOtherCosts" + preferences.getString("dTotalCostCalculated", "0"));

								try {
									
									
									// store string purchase price
									editor.putString("dOtherCosts", vOtherCosts);
									editor.commit();
															
									//convert purchase price to double
									dblOtherCosts = Double.parseDouble(vOtherCosts);	
									
									//get total cost from storage
									String retriveValue = preferences.getString("dTotalCostCalculated", "0");
									Log.d("retriveValue", "log test 4 vOtherCosts " + retriveValue);
									
									// convert to double
									dblTotalCostCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total cost double
									dblNewTotalCostCalculated = dblOtherCosts+ dblTotalCostCalculated;
									
									//convert new total cost calculated and convert to string
									 String stringNewTotalCostCalculated;
									stringNewTotalCostCalculated = String.valueOf(dblNewTotalCostCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalCostCalculated);
									
									//textview Total Cost Calculated
									tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
									
									//insert new total cost to storage
									editor.putString("dTotalCostCalculated", stringNewTotalCostCalculated);
									editor.commit();
									
									tvTotalCostCalculated.setText(stringNewTotalCostCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
						

				
				

				public void setOtherCosts() {

					methods md = new methods();

					etOtherCosts = (EditText) findViewById(R.id.etOtherCosts);
					etOtherCosts.setText(md.retriveSharePreference(this, "vOtherCosts",
							"dOtherCosts"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vOtherCosts",
									"dOtherCosts"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vOtherCosts", "dOtherCosts"));

				}
				
				
				// get deposit paid
				public void getDepositePaid() {
					variables vb = new variables();
					methods md = new methods();
					etDepositePaid = (EditText) findViewById(R.id.etDepositePaid);

					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vDepositePaid " + vDepositePaid);
								vDepositePaid = etDepositePaid.getText().toString();
								
								Log.d("retriveValue", "log test 1 vDepositePaid " + vDepositePaid);
								
								
								Log.d("retriveValue", "log test 2 vDepositePaid" + preferences.getString("dDepositePaid", "0"));

								try {
									
									
									// store string deposite paid
									editor.putString("dDepositePaid", vDepositePaid);
									editor.commit();
															
									//convert deposit paid to double
									dblDepositePaid = Double.parseDouble(vDepositePaid);	
									
									//get total funding from storage
									String retriveValue = preferences.getString("dTotalFundingCalculated", "0");
									Log.d("retriveValue", "log test 4 vDepositePaid " + retriveValue);
									
									// convert to double
									dblTotalFundingCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total funding double
									dblNewTotalFundingCalculated= dblDepositePaid+ dblTotalFundingCalculated;
									
									//convert new total funding calculated and convert to string
									 String stringNewTotalFundingCalculated;
									stringNewTotalFundingCalculated = String.valueOf(dblNewTotalFundingCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalFundingCalculated);
									
									//textview Total funding Calculated
									tvTotalFundingCalculated = (TextView) findViewById(R.id.tvTotalFundingsCalculated); 
									
									//insert new total funding to storage
									editor.putString("dTotalFundingCalculated", stringNewTotalFundingCalculated);
									editor.commit();
									
									tvTotalFundingCalculated.setText(stringNewTotalFundingCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
						

				
				

				public void setDepositePaid() {

					methods md = new methods();

					etDepositePaid = (EditText) findViewById(R.id.etDepositePaid);
					etDepositePaid.setText(md.retriveSharePreference(this, "vDepositePaid",
							"dDepositePaid"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vDepositePaid",
									"dDepositePaid"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vDepositePaid", "dDepositePaid"));

				}
				
				
				// get Saving Contribution
				public void getSavingsContribution() {
					variables vb = new variables();
					methods md = new methods();
					etSavingsContribution = (EditText) findViewById(R.id.etSavingsContribution);

					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vSavingsContribution " + vSavingsContribution);
								vSavingsContribution = etSavingsContribution.getText().toString();
								
								Log.d("retriveValue", "log test 1 vSavingsContribution " + vSavingsContribution);
								
								
								Log.d("retriveValue", "log test 2 vSavingsContribution" + preferences.getString("dSavingsContribution", "0"));

								try {
									
									
									// store string deposite paid
									editor.putString("dSavingsContribution", vSavingsContribution);
									editor.commit();
															
									//convert deposit paid to double
									dblSavingsContribution = Double.parseDouble(vSavingsContribution);	
									
									//get total funding from storage
									String retriveValue = preferences.getString("dTotalFundingCalculated", "0");
									Log.d("retriveValue", "log test 4 vSavingsContribution " + retriveValue);
									
									// convert to double
									dblTotalFundingCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total funding double
									dblNewTotalFundingCalculated= dblSavingsContribution + dblTotalFundingCalculated;
									
									//convert new total funding calculated and convert to string
									 String stringNewTotalFundingCalculated;
									stringNewTotalFundingCalculated = String.valueOf(dblNewTotalFundingCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalFundingCalculated);
									
									//textview Total funding Calculated
									tvTotalFundingCalculated = (TextView) findViewById(R.id.tvTotalFundingsCalculated); 
									
									//insert new total funding to storage
									editor.putString("dTotalFundingCalculated", stringNewTotalFundingCalculated);
									editor.commit();
									
									tvTotalFundingCalculated.setText(stringNewTotalFundingCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
						

				
				

				public void setSavingsContribution() {

					methods md = new methods();

					etSavingsContribution = (EditText) findViewById(R.id.etSavingsContribution);
					etSavingsContribution.setText(md.retriveSharePreference(this, "vSavingsContribution",
							"dSavingsContribution"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vSavingsContribution",
									"dSavingsContribution"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vSavingsContribution", "dSavingsContribution"));

				}
				
				
				
				// get first home owners grant
				public void getFirstHomeOwnersGrant() {
					variables vb = new variables();
					methods md = new methods();
					etFirstHomeOwnersGrant = (EditText) findViewById(R.id.etFirstHomeOwnersGrant);

					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vFirstHomeOwnersGrant " + vFirstHomeOwnersGrant);
								vFirstHomeOwnersGrant = etFirstHomeOwnersGrant.getText().toString();
								
								Log.d("retriveValue", "log test 1 vFirstHomeOwnersGrant " + vFirstHomeOwnersGrant);
								
								
								Log.d("retriveValue", "log test 2 vFirstHomeOwnersGrant" + preferences.getString("dFirstHomeOwnersGrant", "0"));

								try {
									
									
									// store string deposite paid
									editor.putString("dFirstHomeOwnersGrant", vFirstHomeOwnersGrant);
									editor.commit();
															
									//convert deposit paid to double
									dblFirstHomeOwnersGrant = Double.parseDouble(vFirstHomeOwnersGrant);	
									
									//get total funding from storage
									String retriveValue = preferences.getString("dTotalFundingCalculated", "0");
									Log.d("retriveValue", "log test 4 vFirstHomeOwnersGrant " + retriveValue);
									
									// convert to double
									dblTotalFundingCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total funding double
									dblNewTotalFundingCalculated= dblFirstHomeOwnersGrant + dblTotalFundingCalculated;
									
									//convert new total funding calculated and convert to string
									 String stringNewTotalFundingCalculated;
									stringNewTotalFundingCalculated = String.valueOf(dblNewTotalFundingCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalFundingCalculated);
									
									//textview Total funding Calculated
									tvTotalFundingCalculated = (TextView) findViewById(R.id.tvTotalFundingsCalculated); 
									
									//insert new total funding to storage
									editor.putString("dTotalFundingCalculated", stringNewTotalFundingCalculated);
									editor.commit();
									
									tvTotalFundingCalculated.setText(stringNewTotalFundingCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
						

				
				

				public void setFirstHomeOwnersGrant() {

					methods md = new methods();

					etFirstHomeOwnersGrant = (EditText) findViewById(R.id.etFirstHomeOwnersGrant);
					etFirstHomeOwnersGrant.setText(md.retriveSharePreference(this, "vFirstHomeOwnersGrant",
							"dFirstHomeOwnersGrant"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vFirstHomeOwnersGrant",
									"dFirstHomeOwnersGrant"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vFirstHomeOwnersGrant", "dFirstHomeOwnersGrant"));

				}
				
				
				// get Gifts
				public void getGifts() {
					variables vb = new variables();
					methods md = new methods();
					etGifts = (EditText) findViewById(R.id.etGifts);

					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vGifts " + vGifts);
								vGifts = etGifts.getText().toString();
								
								Log.d("retriveValue", "log test 1 vGifts " + vGifts);
								
								
								Log.d("retriveValue", "log test 2 vGifts " + preferences.getString("dGifts", "0"));

								try {
									
									
									// store string deposite paid
									editor.putString("dGifts", vGifts);
									editor.commit();
															
									//convert deposit paid to double
									dblGifts = Double.parseDouble(vGifts);	
									
									//get total funding from storage
									String retriveValue = preferences.getString("dTotalFundingCalculated", "0");
									Log.d("retriveValue", "log test 4 vFirstHomeOwnersGrant " + retriveValue);
									
									// convert to double
									dblTotalFundingCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total funding double
									dblNewTotalFundingCalculated= dblGifts + dblTotalFundingCalculated;
									
									//convert new total funding calculated and convert to string
									 String stringNewTotalFundingCalculated;
									stringNewTotalFundingCalculated = String.valueOf(dblNewTotalFundingCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalFundingCalculated);
									
									//textview Total funding Calculated
									tvTotalFundingCalculated = (TextView) findViewById(R.id.tvTotalFundingsCalculated); 
									
									//insert new total funding to storage
									editor.putString("dTotalFundingCalculated", stringNewTotalFundingCalculated);
									editor.commit();
									
									tvTotalFundingCalculated.setText(stringNewTotalFundingCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
						

				
				

				public void setGifts() {

					methods md = new methods();

					etGifts = (EditText) findViewById(R.id.etGifts);
					etGifts.setText(md.retriveSharePreference(this, "vGifts",
							"dGifts"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vGifts",
									"dGifts"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vGifts", "dGifts"));

				}
				
				
				// get SaleProceeds
				public void getSaleProceeds() {
					variables vb = new variables();
					methods md = new methods();
					etSaleProceeds = (EditText) findViewById(R.id.etSaleProceeds);

					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vSaleProceeds " + vSaleProceeds);
								vSaleProceeds = etSaleProceeds.getText().toString();
								
								Log.d("retriveValue", "log test 1 vSaleProceeds " + vSaleProceeds);
								
								
								Log.d("retriveValue", "log test 2 vSaleProceeds " + preferences.getString("dSaleProceeds", "0"));

								try {
									
									
									// store string deposite paid
									editor.putString("dSaleProceeds", vSaleProceeds);
									editor.commit();
															
									//convert deposit paid to double
									dblSaleProceeds = Double.parseDouble(vSaleProceeds);	
									
									//get total funding from storage
									String retriveValue = preferences.getString("dTotalFundingCalculated", "0");
									Log.d("retriveValue", "log test 4 vFirstHomeOwnersGrant " + retriveValue);
									
									// convert to double
									dblTotalFundingCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total funding double
									dblNewTotalFundingCalculated= dblSaleProceeds + dblTotalFundingCalculated;
									
									//convert new total funding calculated and convert to string
									 String stringNewTotalFundingCalculated;
									stringNewTotalFundingCalculated = String.valueOf(dblNewTotalFundingCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalFundingCalculated);
									
									//textview Total funding Calculated
									tvTotalFundingCalculated = (TextView) findViewById(R.id.tvTotalFundingsCalculated); 
									
									//insert new total funding to storage
									editor.putString("dTotalFundingCalculated", stringNewTotalFundingCalculated);
									editor.commit();
									
									tvTotalFundingCalculated.setText(stringNewTotalFundingCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
						

				
				

				public void setSaleProceeds() {

					methods md = new methods();

					etSaleProceeds = (EditText) findViewById(R.id.etSaleProceeds);
					etSaleProceeds.setText(md.retriveSharePreference(this, "vSaleProceeds",
							"dSaleProceeds"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vSaleProceeds",
									"dSaleProceeds"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vSaleProceeds", "dSaleProceeds"));

				}
				
				
				// get Others
				public void getOthers() {
					variables vb = new variables();
					methods md = new methods();
					etOthers = (EditText) findViewById(R.id.etOthers);

					
							  SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
								SharedPreferences.Editor editor = preferences.edit();
								
								// XXX do something
								System.out.println("vOthers " + vOthers);
								vOthers = etOthers.getText().toString();
								
								Log.d("retriveValue", "log test 1 vOthers " + vOthers);
								
								
								Log.d("retriveValue", "log test 2 vOthers " + preferences.getString("dOthers", "0"));

								try {
									
									
									// store string deposite paid
									editor.putString("dOthers", vOthers);
									editor.commit();
															
									//convert deposit paid to double
									dblOthers = Double.parseDouble(vOthers);	
									
									//get total funding from storage
									String retriveValue = preferences.getString("dTotalFundingCalculated", "0");
									Log.d("retriveValue", "log test 4 vFirstHomeOwnersGrant " + retriveValue);
									
									// convert to double
									dblTotalFundingCalculated = Double.parseDouble(retriveValue);
									
									//calculate new total funding double
									dblNewTotalFundingCalculated= dblOthers + dblTotalFundingCalculated;
									
									//convert new total funding calculated and convert to string
									 String stringNewTotalFundingCalculated;
									stringNewTotalFundingCalculated = String.valueOf(dblNewTotalFundingCalculated);
									Log.d("retriveValue", "log test 5 " + stringNewTotalFundingCalculated);
									
									//textview Total funding Calculated
									tvTotalFundingCalculated = (TextView) findViewById(R.id.tvTotalFundingsCalculated); 
									
									//insert new total funding to storage
									editor.putString("dTotalFundingCalculated", stringNewTotalFundingCalculated);
									editor.commit();
									
									tvTotalFundingCalculated.setText(stringNewTotalFundingCalculated);
									
								} catch (NumberFormatException nfe) {
									System.out.println("num format exception " + nfe);
								} catch (NullPointerException ne){
									System.out.println("null pointer exception " + ne);
								}
						  }
						

				
				

				public void setOthers() {

					methods md = new methods();

					etOthers = (EditText) findViewById(R.id.etOthers);
					etOthers.setText(md.retriveSharePreference(this, "vOthers",
							"dOthers"));
					System.out.println("set purchase price "
							+ md.retriveSharePreference(this, "vOthers",
									"dOthers"));
					
					System.out.println(" set deposit paid1 "+ md.retriveSharePreference(this, "vOthers", "dOthers"));

				}
				
				
				// get OthersSpecify
				public void getOthersSpecify() {
					variables vb = new variables();
					methods md = new methods();
					etOthersSpecify = (EditText) findViewById(R.id.etOthersSpecify);
					vOthersSpecify = etOthersSpecify.getText().toString();
					
					md.editorSharePreferences(this, "dOthersSpecify", vOthersSpecify);
				}
				
				public void setOthersSpecify() {

					methods md = new methods();

					etOthersSpecify = (EditText) findViewById(R.id.etOthersSpecify);
					etOthersSpecify.setText(md.retriveSharePreference(this, "vOthersSpecify",
							"dOthersSpecify"));
					System.out.println("set occupation"
							+ md.retriveSharePreference(this, "vOthersSpecify",
									"dOthersSpecify"));

				}

		
	//get total cost calculated
		public void getTotalCost() {
			methods md = new methods();
			tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
			vTotalCostCalculated = tvTotalCostCalculated.getText().toString();
			md.editorSharePreferences(this, "dTotalCostCalculated", vTotalCostCalculated); 
			
			System.out.println(" get total cost1 " +  vTotalCostCalculated);
			System.out.println(" get total cost2 "+ md.retriveSharePreference(this, "vTotalCost", "dDepositPaid"));
		}

		public void setTotalCost() {
			methods md = new methods();

			tvTotalCostCalculated = (TextView) findViewById(R.id.tvTotalCostsCalculated);
			tvTotalCostCalculated.setText(md.retriveSharePreference(this, "vTotalCost",
					"dTotalCostCalculated"));
			
			System.out.println(" set total cost "+ md.retriveSharePreference(this, "vTotalCost", "dDepositPaid"));
		}
		
		
		//get total funding calculated
				public void getTotalFund() {
					methods md = new methods();
					tvTotalFundingCalculated = (TextView) findViewById(R.id.tvTotalFundingsCalculated);
					vTotalFundingCalculated = tvTotalFundingCalculated.getText().toString();
					md.editorSharePreferences(this, "dTotalFundingCalculated", vTotalFundingCalculated); 
					
					System.out.println(" get total cost1 " +  vTotalFundingCalculated);
					System.out.println(" get total cost2 "+ md.retriveSharePreference(this, "vTotalFunding", "dDepositPaid"));
				}

				public void setTotalFund() {
					methods md = new methods();

					tvTotalFundingCalculated = (TextView) findViewById(R.id.tvTotalFundingsCalculated);
					tvTotalFundingCalculated.setText(md.retriveSharePreference(this, "vTotalFunding",
							"dTotalFundingCalculated"));
					
					System.out.println(" set total cost "+ md.retriveSharePreference(this, "vTotalfunding", "dDepositPaid"));
				}

}
